<?php
header("Content-Type:text/html;charset=utf-8");
include_once '../include/include.php';
c_create::createClass('setPage');
$page = new setPage();
c_create::createClass('news');
$news = new news();
$outvar[headtitle]=$outvar[headtitle]." 新闻检索";
if ($_GET[id]){	
	$cid = trim($_GET['id']);
	$cataname =$news->getOneType($cid);
	$outvar[cataname] = $cataname[Ccataname];
	$childcataitem =$news->getTypeList($cid);	
	if (count($childcataitem)>0)
	{
		$wherequery .= " AND ( A.Cid=$cid OR A.Cid =";
		foreach($childcataitem as $key=>$val)
		{
			$ccitem[]=$key;			
		}
		$getchildcataquery=implode(' OR A.Cid=',$ccitem);
		$wherequery .= $getchildcataquery;
		$wherequery .= ")";
		
	}
	else $wherequery .= " AND A.Cid=$cid ";
	$outvar[id] = $id;
}
if ($_GET[wd]){
	$wd = trim($_GET['wd']);
	$wherequery .= " AND binary ucase(a.Atitle) like concat('%',ucase('".$wd."'),'%')";
	$outvar[search_word] = $wd;
	$outvar[headtitle]=$wd." -- 新闻检索列表 ".$outvar[headtitle];
}

$where = " WHERE a.Adeleted='n' $wherequery ORDER BY a.Ahit DESC, a.Articleid DESC ";
$query = "SELECT COUNT(*) FROM ".TABLE_NEWS.' a'.$where;
$page->setPagePHP(25,10,$dbconn->Getonefield($query));
$query = "SELECT a.Articleid, a.ParentCid, a.Cid, a.Ahot, a.Adate, a.Ahit, a.Atitle,b.Ccataname FROM ".TABLE_NEWS.' a LEFT JOIN '.TABLE_NEWSCATA.' b ON (a.Cid=b.Cid)'.$where.$page->limit;
$nowQueryid = $dbconn->Query($query);
$i = 0;
while ($row = $dbconn->next_record($nowQueryid)){
	$row[num] = $i+1;
	$row[Atitle_sub] = cut_str($row[Atitle],30);
	$row[Atitle_sub] = str_replace($_GET[wd],'<b class="red">'.$_GET[wd].'</b>',$row[Atitle_sub]);
	$row[Adate] = date("Y-m-d",strtotime($row[Adate]));
	$row[Ccataname] = $row[Ccataname]?$row[Ccataname]:'无类';
	
	$array[] = $row;
	$i++;
}
$outvar[page] = $page->menuAll;
$outvar[record] = $array;
//$outvar[fileurl_1] = getFileWithVar('',array('id','did'));
//$outvar[fileurl_2] = getFileWithVar('',array('id','did','Cid'));
$outvar[typelist] = $news->getTypeList();
outFile('search');
?>